﻿package mortal.game.view.systemSetting.view
{
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.common.shortcutsKey.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class ShortcutsPanel extends GSprite
    {
        protected var _btnResetToDefault:GButton;
        protected var _btnOK:GButton;
        protected var _btnCancel:GButton;
        protected var _listModuleKey:GTileList;
        protected var _listSkillsKey:GTileList;

        public function ShortcutsPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(17, 67, 231, 329, this));
            pushUIToDisposeVec(UIFactory.bg(19, 69, 227, 26, this, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.gTextField("功能", 40, 72, 100, 20, this, GlobalStyle.textFormatAnjin));
            pushUIToDisposeVec(UIFactory.gTextField("快捷键", 150, 72, 100, 20, this, GlobalStyle.textFormatAnjin));
            pushUIToDisposeVec(UIFactory.bg(251, 67, 231, 329, this));
            pushUIToDisposeVec(UIFactory.bg(253, 69, 227, 26, this, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.gTextField("快捷栏", 270, 72, 100, 20, this, GlobalStyle.textFormatAnjin));
            pushUIToDisposeVec(UIFactory.gTextField("快捷键", 380, 72, 100, 20, this, GlobalStyle.textFormatAnjin));
            var _loc_1:* = ShortcutsKey.instance.moduleAry;
            this._listModuleKey = UIFactory.tileList(17, 95, 228, 298, this);
            this._listModuleKey.rowHeight = 30;
            this._listModuleKey.columnWidth = 210;
            this._listModuleKey.setStyle("cellRenderer", ShortcutItemRenderer);
            this._listModuleKey.dataProvider = new DataProvider(_loc_1);
            this._listModuleKey.drawNow();
            pushUIToDisposeVec(this._listModuleKey);
            var _loc_2:* = ShortcutsKey.instance.skillsAry;
            this._listSkillsKey = UIFactory.tileList(251, 95, 228, 298, this);
            this._listSkillsKey.rowHeight = 30;
            this._listSkillsKey.columnWidth = 210;
            this._listSkillsKey.setStyle("cellRenderer", ShortcutItemRenderer);
            this._listSkillsKey.dataProvider = new DataProvider(_loc_2);
            this._listSkillsKey.drawNow();
            pushUIToDisposeVec(this._listSkillsKey);
            this._btnResetToDefault = UIFactory.gButton("恢复默认", 97, 402, 64, 22, this);
            pushUIToDisposeVec(this._btnResetToDefault);
            this._btnOK = UIFactory.gButton("确定", 277, 402, 64, 22, this);
            pushUIToDisposeVec(this._btnOK);
            this._btnResetToDefault.configEventListener(MouseEvent.CLICK, this.onClickResetToDefault);
            this._btnOK.configEventListener(MouseEvent.CLICK, this.onClickOK);
            Dispatcher.addEventListener(EventName.ShortcutsUpdate, this.onShortcutsUpdateHandler);
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }// end function

        private function onShortcutsUpdateHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as KeyMapData;
            if (_loc_2)
            {
                if (ShortcutsKey.instance.skillsAry.indexOf(_loc_2) > -1)
                {
                    this._listSkillsKey.invalidateItem(_loc_2);
                }
                else if (ShortcutsKey.instance.moduleAry.indexOf(_loc_2) > -1)
                {
                    this._listModuleKey.invalidateItem(_loc_2);
                }
            }
            return;
        }// end function

        protected function onClickResetToDefault(event:MouseEvent) : void
        {
            ShortcutsKey.instance.setDefaultShortcutsKey();
            this._listModuleKey.invalidateList();
            this._listSkillsKey.invalidateList();
            this.save();
            return;
        }// end function

        protected function onClickOK(event:MouseEvent) : void
        {
            this.save();
            return;
        }// end function

        protected function save() : void
        {
            var _loc_1:* = new Object();
            _loc_1.type = SystemSettingType.SystemKeyMapData;
            _loc_1.value = ShortcutsKey.instance.getServerStr();
            Dispatcher.dispatchEvent(new DataEvent(EventName.SystemSettingSava, _loc_1));
            return;
        }// end function

        protected function onClickCancel(event:MouseEvent) : void
        {
            this.recoverySet();
            return;
        }// end function

        protected function onRemoveFromStage(event:Event) : void
        {
            ShortcutsKey.instance.recoverySetter();
            return;
        }// end function

        protected function recoverySet() : void
        {
            ShortcutsKey.instance.recoverySetter();
            this._listModuleKey.invalidateList();
            this._listSkillsKey.invalidateList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            Dispatcher.removeEventListener(EventName.ShortcutsUpdate, this.onShortcutsUpdateHandler);
            return;
        }// end function

    }
}
